﻿@model PagedList<YiYiTong.Rocket.Model.Manager.RoleModel>
@{
    ViewBag.Title = "角色管理";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<form id="S_Form" class="form-inline definewidth m20" action="@Url.Action("RoleList", "Role")" method="get">
    <p>
        角色代码：
        <input type="text" name="roleCode" id="roleCode" class="abc input-default" placeholder="" value="@Request.QueryString["roleCode"]">&nbsp;
        角色名称：
        <input type="text" name="roleName" id="roleName" class="abc input-default" placeholder="" value="@Request.QueryString["roleName"]">&nbsp;
        <button type="submit" class="btn btn-primary">查询</button>&nbsp;&nbsp; <button type="button" class="btn btn-success" id="addnew">添加角色</button>
    </p>
</form>
<table class="table table-bordered table-hover definewidth m10">
    <thead>
        <tr>
            <th>角色编号</th>
            <th>角色代码</th>
            <th>角色名称</th>
            <th>备注</th>
            <th>管理操作</th>
        </tr>
    </thead>
    @if (Model != null && Model.Count != 0)
        
    {
        foreach (var m in Model)
        {
            <tr>
                <td>@m.roleId</td>
                <td>@m.roleCode</td>
                <td>@m.roleName</td>
                <td>@m.remark</td>
                <td>
                    <a href="@Url.Action("AddRole", "Role", new { RoleId = m.roleId })">编辑</a>
                    <a href="@Url.Action("SetMenu", "Role", new { RoleId = m.roleId, RoleName = m.roleName })">设置菜单</a>
                    <a href="@Url.Action("SetAction", "Role", new { RoleId = m.roleId, RoleName = m.roleName })">设置功能</a>
                    <a href="javascript:void(0);" onclick="Delete(@m.roleId)">删除</a>
                </td>
            </tr>
        }
    }
</table>
<div class="inline pull-right page">
    @if (Model != null)
    {
        @Html.Pager(Model, new PagerOptions { ContainerTagName = "div", PagerItemTemplate = "{0}", CurrentPagerItemTemplate = "<span class='current'>{0}</span>", DisabledPagerItemTemplate = "<span class=\"disabled\">{0}</span>", Id = "flickrpager" })
    }
</div>
<script>
    BUI.use(['bui/form', 'bui/overlay'], function (Form, overlay) {
        new Form.Form({
            srcNode: '#S_Form'
        }).render();
    });

    function Delete(RoleId) {
        BUI.Message.Show({
            title: '提示',
            msg: '确定要删除该角色吗?',
            icon: 'question',
            buttons: [
              {
                  text: '确定',
                  elCls: 'button button-primary',
                  handler: function () {
                      url = "@Url.Action("DelRole", "Role")";
                      parameter = { RoleId: RoleId };
                      $.post(url, parameter, function (result) {
                          if (result.Message != undefined) {
                              if (result.IsSuccess) {
                                  BUI.Message.Alert(result.Message, function () {
                                      location.href = result.Body;
                                  }, 'success');
                              }
                              else {
                                  BUI.Message.Alert(result.Message, 'error');
                              }
                          }
                          else {
                              var substr = cutstr(result, "BUI.Message.Alert", "function");
                              substr = substr.replace("'", "").replace("'", "").replace("(", "").replace(",", "");
                              if (substr == "")
                                  BUI.Message.Alert("操作失败，请联系技术人员", 'warning');
                              else {
                                  if (substr.indexOf("请重新登录") > 0) {
                                      BUI.Message.Alert(substr, function () {
                                          top.location.href = "@Url.Action("Login","User")";
                                      }, 'warning');
                                  }
                                  else {
                                      BUI.Message.Alert(substr, 'warning');
                                  }
                              }
                          }
                      });
                      this.close();
                  }
              },
              {
                  text: '取消',
                  elCls: 'button',
                  handler: function () {
                      this.close();
                  }
              }

            ]
        });
    }

    $(function () {
        $('#addnew').on('click', function () {
            window.document.location.href = "@Url.Action("AddRole", "Role")";
        });
    });
</script>
